<template>
  <el-dialog v-drag :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
      label-width="80px">
      <el-form-item label="产品编号" prop="goodsCode">
        <el-input size="mini" v-model="dataForm.goodsCode" placeholder="产品编号"></el-input>
      </el-form-item>
      <el-form-item label="产品名称" prop="goodsName">
        <el-input size="mini" v-model="dataForm.goodsName" placeholder="产品名称"></el-input>
      </el-form-item>
      <el-form-item label="类别id" prop="categoryId">
        <el-input size="mini" v-model="dataForm.categoryId" placeholder="类别id"></el-input>
      </el-form-item>
      <el-form-item label="类别名称" prop="categoryName">
        <el-input size="mini" v-model="dataForm.categoryName" placeholder="类别名称"></el-input>
      </el-form-item>
      <el-form-item label="通用名" prop="genericName">
        <el-input size="mini" v-model="dataForm.genericName" placeholder="通用名"></el-input>
      </el-form-item>
      <el-form-item label="产品区域" prop="producingArea">
        <el-input size="mini" v-model="dataForm.producingArea" placeholder="产品区域"></el-input>
      </el-form-item>
      <el-form-item label="供应商id" prop="supplierId">
        <el-input size="mini" v-model="dataForm.supplierId" placeholder="供应商id"></el-input>
      </el-form-item>
      <el-form-item label="供应商名称" prop="supplierName">
        <el-input size="mini" v-model="dataForm.supplierName" placeholder="供应商名称"></el-input>
      </el-form-item>
      <el-form-item label="供应商联系方式" prop="supplierMobile">
        <el-input size="mini" v-model="dataForm.supplierMobile" placeholder="供应商联系方式"></el-input>
      </el-form-item>
      <el-form-item label="规格" prop="standard">
        <el-input size="mini" v-model="dataForm.standard" placeholder="规格"></el-input>
      </el-form-item>
      <el-form-item label="单位" prop="unit">
        <el-input size="mini" v-model="dataForm.unit" placeholder="单位"></el-input>
      </el-form-item>
      <el-form-item label="助记名" prop="mnemonicName">
        <el-input size="mini" v-model="dataForm.mnemonicName" placeholder="助记名"></el-input>
      </el-form-item>
      <el-form-item label="批号" prop="batchNo">
        <el-input size="mini" v-model="dataForm.batchNo" placeholder="批号"></el-input>
      </el-form-item>
      <el-form-item label="采购批次号" prop="purchaseSerialNo">
        <el-input size="mini" v-model="dataForm.purchaseSerialNo" placeholder="采购批次号"></el-input>
      </el-form-item>
      <el-form-item label="入库号" prop="storageNo">
        <el-input size="mini" v-model="dataForm.storageNo" placeholder="入库号"></el-input>
      </el-form-item>
      <el-form-item label="验收号" prop="acceptNo">
        <el-input size="mini" v-model="dataForm.acceptNo" placeholder="验收号"></el-input>
      </el-form-item>
      <el-form-item label="采购号" prop="receiveNo">
        <el-input size="mini" v-model="dataForm.receiveNo" placeholder="采购号"></el-input>
      </el-form-item>
      <el-form-item label="订货单号" prop="orderNo">
        <el-input size="mini" v-model="dataForm.orderNo" placeholder="订货单号"></el-input>
      </el-form-item>
      <el-form-item label="供应商配送单号" prop="supplierDeliveryNo">
        <el-input size="mini" v-model="dataForm.supplierDeliveryNo" placeholder="供应商配送单号"></el-input>
      </el-form-item>
      <el-form-item label="采购发票号" prop="purchaseinvoiceNo">
        <el-input size="mini" v-model="dataForm.purchaseinvoiceNo" placeholder="采购发票号"></el-input>
      </el-form-item>
      <el-form-item label="采购发票编码" prop="purchaseinvoiceCode">
        <el-input size="mini" v-model="dataForm.purchaseinvoiceCode" placeholder="采购发票编码"></el-input>
      </el-form-item>
      <el-form-item label="库存" prop="stockNum">
        <el-input size="mini" v-model="dataForm.stockNum" placeholder="库存"></el-input>
      </el-form-item>
      <el-form-item label="采购数量" prop="purchaseNum">
        <el-input size="mini" v-model="dataForm.purchaseNum" placeholder="采购数量"></el-input>
      </el-form-item>
      <el-form-item label="采购退货数量" prop="returnNum">
        <el-input size="mini" v-model="dataForm.returnNum" placeholder="采购退货数量"></el-input>
      </el-form-item>
      <el-form-item label="拆零数量" prop="splitNum">
        <el-input size="mini" v-model="dataForm.splitNum" placeholder="拆零数量"></el-input>
      </el-form-item>
      <el-form-item label="销售数量" prop="saleNum">
        <el-input size="mini" v-model="dataForm.saleNum" placeholder="销售数量"></el-input>
      </el-form-item>
      <el-form-item label="盘盈数量" prop="checkInNum">
        <el-input size="mini" v-model="dataForm.checkInNum" placeholder="盘盈数量"></el-input>
      </el-form-item>
      <el-form-item label="盘亏数量" prop="checkOutNum">
        <el-input size="mini" v-model="dataForm.checkOutNum" placeholder="盘亏数量"></el-input>
      </el-form-item>
      <el-form-item label="销毁数量" prop="destroyNum">
        <el-input size="mini" v-model="dataForm.destroyNum" placeholder="销毁数量"></el-input>
      </el-form-item>
      <el-form-item label="采购价" prop="purchasePrice">
        <el-input size="mini" v-model="dataForm.purchasePrice" placeholder="采购价"></el-input>
      </el-form-item>
      <el-form-item label="指导零售价" prop="guidePrice">
        <el-input size="mini" v-model="dataForm.guidePrice" placeholder="指导零售价"></el-input>
      </el-form-item>
      <el-form-item label="售价" prop="salePrice">
        <el-input size="mini" v-model="dataForm.salePrice" placeholder="售价"></el-input>
      </el-form-item>
      <el-form-item label="会员价" prop="memberPrice">
        <el-input size="mini" v-model="dataForm.memberPrice" placeholder="会员价"></el-input>
      </el-form-item>
      <el-form-item label="条码" prop="barCode">
        <el-input size="mini" v-model="dataForm.barCode" placeholder="条码"></el-input>
      </el-form-item>
      <el-form-item label="是否处方药1是" prop="isRxDrug">
        <el-input size="mini" v-model="dataForm.isRxDrug" placeholder="是否处方药1是"></el-input>
      </el-form-item>
      <el-form-item label="批准文号" prop="approvalNo">
        <el-input size="mini" v-model="dataForm.approvalNo" placeholder="批准文号"></el-input>
      </el-form-item>
      <el-form-item label="厂家" prop="produceFactory">
        <el-input size="mini" v-model="dataForm.produceFactory" placeholder="厂家"></el-input>
      </el-form-item>
      <el-form-item label="剂型" prop="dosageForm">
        <el-input size="mini" v-model="dataForm.dosageForm" placeholder="剂型"></el-input>
      </el-form-item>
      <el-form-item label="有效期" prop="expiredDate">
        <el-input size="mini" v-model="dataForm.expiredDate" placeholder="有效期"></el-input>
      </el-form-item>
      <el-form-item label="是否医保" prop="isMedicare">
        <el-input size="mini" v-model="dataForm.isMedicare" placeholder="是否医保"></el-input>
      </el-form-item>
      <el-form-item label="是否中药" prop="isChinaDrug">
        <el-input size="mini" v-model="dataForm.isChinaDrug" placeholder="是否中药"></el-input>
      </el-form-item>
      <el-form-item label="是否gmp药" prop="isGmp">
        <el-input size="mini" v-model="dataForm.isGmp" placeholder="是否gmp药"></el-input>
      </el-form-item>
      <el-form-item label="效果" prop="effect">
        <el-input size="mini" v-model="dataForm.effect" placeholder="效果"></el-input>
      </el-form-item>
      <el-form-item label="品牌id" prop="brandId">
        <el-input size="mini" v-model="dataForm.brandId" placeholder="品牌id"></el-input>
      </el-form-item>
      <el-form-item label="品牌名称" prop="brandName">
        <el-input size="mini" v-model="dataForm.brandName" placeholder="品牌名称"></el-input>
      </el-form-item>
      <el-form-item label="是否提成 1是" prop="isCommission">
        <el-input size="mini" v-model="dataForm.isCommission" placeholder="是否提成 1是"></el-input>
      </el-form-item>
      <el-form-item label="提成比例" prop="commissionRatio">
        <el-input size="mini" v-model="dataForm.commissionRatio" placeholder="提成比例"></el-input>
      </el-form-item>
      <el-form-item label="经办人(入库审批人)" prop="operatorName">
        <el-input size="mini" v-model="dataForm.operatorName" placeholder="经办人(入库审批人)"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input size="mini" v-model="dataForm.remark" placeholder="备注"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data() {
      return {
        visible: false,
        dataForm: {
          id: 0,
          productCode: '',
          productName: '',
          categoryId: '',
          categoryName: '',
          genericName: '',
          producingArea: '',
          supplierId: '',
          supplierName: '',
          supplierMobile: '',
          standard: '',
          unit: '',
          mnemonicName: '',
          batchNo: '',
          purchaseSerialNo: '',
          storageNo: '',
          acceptNo: '',
          receiveNo: '',
          orderNo: '',
          supplierDeliveryNo: '',
          purchaseinvoiceNo: '',
          purchaseinvoiceCode: '',
          stockNum: '',
          purchaseNum: '',
          returnNum: '',
          splitNum: '',
          saleNum: '',
          checkInNum: '',
          checkOutNum: '',
          destroyNum: '',
          purchasePrice: '',
          guidePrice: '',
          salePrice: '',
          memberPrice: '',
          barCode: '',
          isRxDrug: '',
          approvalNo: '',
          produceFactory: '',
          dosageForm: '',
          expiredDate: '',
          isMedicare: '',
          isChinaDrug: '',
          isGmp: '',
          effect: '',
          brandId: '',
          brandName: '',
          isCommission: '',
          commissionRatio: '',
          operatorName: '',
          storeId: '',
          storeName: '',
          storeCode: '',
          createTime: '',
          updateTime: '',
          createUsername: '',
          createUserId: '',
          updateUsername: '',
          updateUserId: '',
          status: '',
          isDeteled: '',
          remark: '',
          version: ''
        },
        dataRule: {
          productCode: [{
            required: true,
            message: '产品编号不能为空',
            trigger: 'blur'
          }],
          productName: [{
            required: true,
            message: '产品名称不能为空',
            trigger: 'blur'
          }],
          categoryId: [{
            required: true,
            message: '类别id不能为空',
            trigger: 'blur'
          }],
          categoryName: [{
            required: true,
            message: '类别名称不能为空',
            trigger: 'blur'
          }],
          genericName: [{
            required: true,
            message: '通用名不能为空',
            trigger: 'blur'
          }],
          producingArea: [{
            required: true,
            message: '产品区域不能为空',
            trigger: 'blur'
          }],
          supplierId: [{
            required: true,
            message: '供应商id不能为空',
            trigger: 'blur'
          }],
          supplierName: [{
            required: true,
            message: '供应商名称不能为空',
            trigger: 'blur'
          }],
          supplierMobile: [{
            required: true,
            message: '供应商联系方式不能为空',
            trigger: 'blur'
          }],
          standard: [{
            required: true,
            message: '规格不能为空',
            trigger: 'blur'
          }],
          unit: [{
            required: true,
            message: '单位不能为空',
            trigger: 'blur'
          }],
          mnemonicName: [{
            required: true,
            message: '助记名不能为空',
            trigger: 'blur'
          }],
          batchNo: [{
            required: true,
            message: '批号不能为空',
            trigger: 'blur'
          }],
          purchaseSerialNo: [{
            required: true,
            message: '采购批次号不能为空',
            trigger: 'blur'
          }],
          storageNo: [{
            required: true,
            message: '入库号不能为空',
            trigger: 'blur'
          }],
          acceptNo: [{
            required: true,
            message: '验收号不能为空',
            trigger: 'blur'
          }],
          supplierDeliveryNo: [{
            required: true,
            message: '供应商配送单号不能为空',
            trigger: 'blur'
          }],
          purchaseinvoiceNo: [{
            required: true,
            message: '采购发票号不能为空',
            trigger: 'blur'
          }],
          purchaseinvoiceCode: [{
            required: true,
            message: '采购发票编码不能为空',
            trigger: 'blur'
          }],
          stockNum: [{
            required: true,
            message: '库存不能为空',
            trigger: 'blur'
          }],
          purchaseNum: [{
            required: true,
            message: '采购数量不能为空',
            trigger: 'blur'
          }],
          returnNum: [{
            required: true,
            message: '采购退货数量不能为空',
            trigger: 'blur'
          }],
          splitNum: [{
            required: true,
            message: '拆零数量不能为空',
            trigger: 'blur'
          }],
          saleNum: [{
            required: true,
            message: '销售数量不能为空',
            trigger: 'blur'
          }],
          checkInNum: [{
            required: true,
            message: '盘盈数量不能为空',
            trigger: 'blur'
          }],
          checkOutNum: [{
            required: true,
            message: '盘亏数量不能为空',
            trigger: 'blur'
          }],
          destroyNum: [{
            required: true,
            message: '销毁数量不能为空',
            trigger: 'blur'
          }],
          purchasePrice: [{
            required: true,
            message: '采购价不能为空',
            trigger: 'blur'
          }],
          guidePrice: [{
            required: true,
            message: '指导零售价不能为空',
            trigger: 'blur'
          }],
          salePrice: [{
            required: true,
            message: '售价不能为空',
            trigger: 'blur'
          }],
          memberPrice: [{
            required: true,
            message: '会员价不能为空',
            trigger: 'blur'
          }],
          barCode: [{
            required: true,
            message: '条码不能为空',
            trigger: 'blur'
          }],
          isRxDrug: [{
            required: true,
            message: '是否处方药1是不能为空',
            trigger: 'blur'
          }],
          approvalNo: [{
            required: true,
            message: '批准文号不能为空 ',
            trigger: 'blur'
          }],
          produceFactory: [{
            required: true,
            message: '厂家不能为空',
            trigger: 'blur'
          }],
          dosageForm: [{
            required: true,
            message: '剂型不能为空',
            trigger: 'blur'
          }],
          expiredDate: [{
            required: true,
            message: '有效期不能为空',
            trigger: 'blur'
          }],
          isMedicare: [{
            required: true,
            message: '是否医保不能为空',
            trigger: 'blur'
          }],
          isChinaDrug: [{
            required: true,
            message: '是否中药不能为空',
            trigger: 'blur'
          }],
          isGmp: [{
            required: true,
            message: '是否gmp药不能为空',
            trigger: 'blur'
          }],
          effect: [{
            required: true,
            message: '效果不能为空',
            trigger: 'blur'
          }],
          brandId: [{
            required: true,
            message: '品牌id不能为空',
            trigger: 'blur'
          }],
          brandName: [{
            required: true,
            message: '品牌名称不能为空',
            trigger: 'blur'
          }],
          isCommission: [{
            required: true,
            message: '是否提成 1是不能为空',
            trigger: 'blur'
          }],
          commissionRatio: [{
            required: true,
            message: '提成比例不能为空',
            trigger: 'blur'
          }],
          operatorName: [{
            required: true,
            message: '经办人(入库审批人)不能为空',
            trigger: 'blur'
          }],
          storeId: [{
            required: true,
            message: '门店id不能为空',
            trigger: 'blur'
          }],
          storeName: [{
            required: true,
            message: '门店名称不能为空',
            trigger: 'blur'
          }],
          storeCode: [{
            required: true,
            message: '门店编码不能为空',
            trigger: 'blur'
          }],
          createTime: [{
            required: true,
            message: '创建时间不能为空',
            trigger: 'blur'
          }],
          updateTime: [{
            required: true,
            message: '修改时间不能为空',
            trigger: 'blur'
          }],
          createUsername: [{
            required: true,
            message: '创建人不能为空',
            trigger: 'blur'
          }],
          createUserId: [{
            required: true,
            message: '创建人id不能为空',
            trigger: 'blur'
          }],
          updateUsername: [{
            required: true,
            message: '修改人不能为空',
            trigger: 'blur'
          }],
          updateUserId: [{
            required: true,
            message: '修改人id不能为空',
            trigger: 'blur'
          }],
          status: [{
            required: true,
            message: '是否可用 1:是不能为空',
            trigger: 'blur'
          }],
          isDeteled: [{
            required: true,
            message: '是否删除 1:是不能为空',
            trigger: 'blur'
          }],
          remark: [{
            required: true,
            message: '备注不能为空',
            trigger: 'blur'
          }],
          version: [{
            required: true,
            message: '版本号不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      init(id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/goods/goodsstock/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.dataForm = data.goodsStock
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/goods/goodsstock/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData(this.dataForm)
            }).then(({
              data
            }) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
